import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';
import 'styleCommon.dart';

class ReturnLineUp extends StatelessWidget {
  final List items;
  ReturnLineUp({Key? key, required this.items}) : super(key: key);
  @override
  Widget build(BuildContext context) {
    return getChatTemplate();
  }

  Widget getChatTemplate() {
    Map leftData = {};
    List<Widget> tiles = [];
    Widget content;
    for (int i = 0; i < this.items.length; i++) {
      if (i == 0) {
        leftData = this.items[i];
      } else {
        tiles.add(returnLineUpInfo(this.items[i]['title'] ?? '无',
            this.items[i]['text'] ?? '无', this.items[i]['queueStatus'],
            sign: this.items[i]['sign'].toString()));
      }
    }
    content = new Column(children: tiles);
    return Flex(
      direction: Axis.horizontal,
      children: <Widget>[
        Expanded(
          flex: 1,
          child: Column(
            crossAxisAlignment: CrossAxisAlignment.start,
            children: [
              Container(
                child: Text(leftData['title'], style: fontStyle1),
              ),
              Container(
                margin: EdgeInsets.only(top: 4),
                child: Text(leftData['text'],
                    style: TextStyle(fontSize: 36.0, color: Color(0xFF414B67))),
              ),
            ],
          ),
        ),
        Expanded(
          flex: 1,
          child: content,
        ),
      ],
    );
  }

  // 排队信息内容 sign 1代表按钮  0 代表文本
  Widget returnLineUpInfo(String title, String content, queueStatus,
      {String sign = "0"}) {
    return Container(
      margin: EdgeInsets.only(bottom: 2),
      child: Row(
        children: <Widget>[
          Text(title, style: fontStyle1),
          Expanded(
            child: Text(''), // 中间用Expanded控件
          ),
          returnContent(content, queueStatus, sign),
        ],
      ),
    );
  }

// Text或者Container
  Widget returnContent(content, queueStatus, String sign) {
    if (sign == '1') {
      return Container(
          padding: EdgeInsets.fromLTRB(5, 1, 5, 2),
          color: queueStatus == 3 ? blueColor : mainColor,
          child: Text(content,
              style: TextStyle(fontSize: 12.0, color: Colors.white)));
    } else {
      return Text(content, style: fontStyle2);
    }
  }
}
